<?php
$this->menu = array(
	array('label'=>'商品管理列表', 'url'=>array('admin'), 'visible'=>Yii::app()->user->v('manage@GoodsAdmin')),
);
$cs = Yii::app()->clientScript;
$cs->registerScriptFile(BASE_URL . '/js/jquery_plus/jquery.form.js', CClientScript::POS_END);
$cs->registerScript('mutil_spec',
	//是否开启了多规格
	'var MUTIL_SPEC = ' . (isset($model['specs']) && count($model['specs']) > 0?'true':'false') . ';'
, CClientScript::POS_END);
$spec_names = array(
	'大小', '颜色', '尺寸', '容量', '口味', '包装', '款式', '型号'
);
$units = array(
	'个', '件', '袋', '斤', '瓶', '双', '箱', '台'
);
?>
<h2><a href="/manage/goods/admin">商品管理列表</a> > 商品编辑</h2>
<?php 
$this->beginWidget('CActiveForm', array(
	'id'			=> 'goods_cate_form',
	'htmlOptions' 	=> array('class'=>'setting_form'),
));
?>
	<div class="setting_nav"></div>
	<dl class="setting_content">
		<dt>基本信息</dt>
		<dd>
			<strong>商品名称：</strong>
			<?php echo YHtml::activeTextField($model, 'name', array('model'=>'Goods', 'rule'=>'^.{1,50}$', 'next_focus'=>''))?>
		</dd>
		<dd>
			<strong>商品编号：</strong>
			<?php echo YHtml::activeTextField($model, 'code', array('model'=>'Goods', 'rule'=>'^$|^.{1,50}$', 'next_focus'=>''))?>
		</dd>
		<dd>
			<strong>单位：</strong>
			<?php 
			$this->widget('manage.widget.YSelectorWidget', array(
				'default_text' 	=> '点击设置单位',
				'name'			=> 'Goods[unit]',
				'options' 		=> $units,
				'value'			=> isset($model['unit'])?$model['unit']:DEFAULT_UNIT,
				'value_text'	=> isset($model['unit'])?$model['unit']:DEFAULT_UNIT,
				'title'			=> '请设置商品单位',
				'rule'			=> '^.+$',
				'on_show'		=> 'on_text_selector_selected'
			));
			?>
		</dd>
		<dd>
			<strong>分类：</strong>
			<?php 
			$cates = isset($model['cate']) ? $model['cate'] : null;
			$this->widget('manage.widget.YSelectorWidget', array(
				'default_text' 	=> '点击设置分类',
				'name'			=> 'Goods[cate][]',
				'tpl' 			=> 'mutil_select',
				'options' 		=> GoodsCateModel::getTree(),
				'value'			=> $cates,
				'value_text'	=> GoodsCateModel::getName($cates, '.', '<br>'),
				'title'			=> '请选择商品分类',
// 				'on_show'		=> 'on_text_selector_selected'
			));
			?>
			<p>
				<?php 
				echo YHtml::link('添加商品分类', '/Manage/GoodsCate/Edit', array(
					'visible'	=> Yii::app()->user->v('manage@GoodsCateEdit')
				))
				?>
			</p>
		</dd>
		<dd>
			<strong>品牌：</strong>
			<?php echo YHtml::activeDropDownList($model, 'brand', BrandModel::getOpts(true, '--空白--'), array('model'=>'Goods', 'next_focus'=>''))?>
			<p>
				<?php 
				echo YHtml::link('添加新品牌', '/Manage/Brand/Edit', array(
					'visible'	=> Yii::app()->user->v('manage@BrandEdit')
				))
				?>
			</p>
		</dd>
		<dd>
			<strong>上下架：</strong>
			<?php echo YHtml::activeDropDownList($model, 'status', GoodsModel::getStatusOpts(), array('model'=>'Goods'))?>
			<p>下载后，商品将不会再前端展示</p>
		</dd>
		<dd>
			<strong>排序：</strong>
			<?php echo YHtml::activeTextField($model, 'rank', array('model'=>'Goods', 'next_focus'=>'', 'rule'=>'^\d+$'))?>
			<p>越小排序越靠前</p>
		</dd>
		<dd>
			<strong>最低限购：</strong>
			<?php 
			$this->widget('application.widget.NumberInputWidget', array(
				'inputOptions' 	=> array('class'=>'limit_count'),
				'name'			=> 'Goods[min]',
				'min'			=> 1,
				'value'			=> isset($model['min'])?$model['min']:null,
				'rule'			=> '^$|^\d+$'
			));
			?>
			<p>每订单最低订货数量限制，留空或0表示不限制</p>
		</dd>
		<dd>
			<strong>最高限购：</strong>
			<?php 
			$this->widget('application.widget.NumberInputWidget', array(
				'inputOptions' 	=> array('class'=>'limit_count'),
				'name'			=> 'Goods[max]',
				'min'			=> 1,
				'value'			=> isset($model['max'])?$model['max']:null,
				'rule'			=> '^$|^\d+$'
			));
			?>
			<p>每订单最高订货数量限制，留空或0表示不限制</p>
		</dd>
		<dt>商品标识</dt>
		<dd>
			<strong>标识：</strong>
			<?php 
			$this->widget('manage.widget.EnumsSelectorWidget', array(
				'code' => 'goods_flag',
				'name' => 'Goods[goods_flag][]',
				'values' => isset($model['goods_flag'])?$model['goods_flag']:null
			));
			?>
		</dd>
		<dt>规格/库存/价格</dt>
		<dd>
			<strong>多规格：</strong>
			<label>
				<input type="checkbox" name="specs" value="1" id="open_specs" />
			开启多规格
			</label>
			<p>最多支持两个维度的规格 <span class="red" id="mutil_error"></span></p>
		</dd>
		<dd>
			<strong>市场参考价：</strong>
			<?php echo YHtml::activeTextField($model, 'market_price', array('model'=>'Goods', 'next_focus'=>'', 'rule'=>'^$|^\d+\.?\d{0,2}$'))?>
			<p>市场参考价，将使用删除线</p>
		</dd>
		<dd class="no_mutil_spec">
			<strong>库存：</strong>
			<?php echo YHtml::activeTextField($model, 'stock', array('model'=>'Goods', 'next_focus'=>'', 'rule'=>'^\-?\d+$'))?>
			<p>销售完后不可下单，负数为不限制库存</p>
		</dd>
		<dd class="no_mutil_spec last_dd">
			<strong>价格：</strong>
			<?php echo YHtml::activeTextField($model, 'price', array('model'=>'Goods', 'next_focus'=>'', 'rule'=>'^\\d+\.?\d*$'))?>
			<p>商品价格</p>
		</dd>
		<dd class="mutil_spec">
			<table class="y_table">
				<tr>
					<th>
					<?php 
					$this->widget('manage.widget.YSelectorWidget', array(
						'default_text' 	=> '点击设置规格维度1',
						'name'			=> 'Goods[spec1]',
						'options' 		=> $spec_names,
						'value'			=> isset($model['spec1'])?$model['spec1']:null,
						'value_text'	=> isset($model['spec1'])?$model['spec1']:null,
						'title'			=> '请设置规格维度1',
						'rule'			=> '^.+$',
						'on_show'		=> 'on_text_selector_selected'
					));
					?>
					</th>
					<th>
					<?php 
					$this->widget('manage.widget.YSelectorWidget', array(
						'default_text' 	=> '点击设置规格维度2',
						'title'			=> '请设置规格维度2',
						'value'			=> isset($model['spec2'])?$model['spec2']:null,
						'value_text'	=> isset($model['spec2'])?$model['spec2']:null,
						'name'			=> 'Goods[spec2]',
						'options' 		=> $spec_names,
						'on_show'		=> 'on_text_selector_selected'
					));
					?>
					</th>
					<th>价格</th>
					<th>库存</th>
					<th>操作</th>
				</tr>
				<?php
				if(isset($model['specs'])){
					$goods_specs = $model['specs'];
				}else{
					$goods_specs = array();
				}
				for($i=count($goods_specs); $i<5; ++$i){
					$goods_specs[]  = array(
						'spec1' => '',
						'spec2' => '',
						'price' => '0.00',
						'stock' => '-1',
					);
				}
				$i = 0;
				foreach($goods_specs as $goods_spec_id => $item){
				?>
				<tr class="row">
					<td><input type="text" name="spec1[<?php echo $goods_spec_id; ?>]" value="<?php echo isset($item['spec1'])?$item['spec1']:''?>" next_focus rule="^$|^.*$"/></td>
					<td><input type="text" name="spec2[<?php echo $goods_spec_id; ?>]" value="<?php echo isset($item['spec2'])?$item['spec2']:''?>" next_focus rule="^$|^.*$"/></td>
					<td><input type="text" name="spec_price[<?php echo $goods_spec_id; ?>]" value="<?php echo isset($item['price'])?$item['price']:'0.00'?>" next_focus rule="^$|^\d+\.?\d{0,2}$" class="right"/></td>
					<td><input type="text" name="spec_stock[<?php echo $goods_spec_id; ?>]" value="<?php echo isset($item['stock'])?$item['stock']:'-1'?>" next_focus rule="^$|^\-?\d{1,4}$" class="right"/></td>
					<td>
					<?php
						echo CHtml::link('复制', 'javascript:void(0)', array('class'=>'add_spec'));
						if($i > 0){
							echo ' | ' . CHtml::link('删除', 'javascript:void(0)', array('class'=>'del_spec'));
						}
					?>
					</td>
				</tr>
				<?php 
					++$i;
				}
				?>
			</table>
		</dd>
		<dt>商品描述</dt>
		<dd>
			<?php 
			$this->widget('application.widget.EditorWidget',array(
				'name'	=> 'Goods[desc]',
				'id'	=> 'editor_desc',
				'value' => (isset($model['desc'])?$model['desc']:''),
			));
			?>
		</dd>
		<dt>商品图片</dt>
		<dd>
			<strong>展示方式：</strong>
			<?php echo YHtml::activeDropDownList($model, 'img_show_type', array('normal'=>'常规展示', '3d'=>'3D展示'), array('model'=>'Goods', 'next_focus'=>''))?>
			<p>界面上图片的展示方式</p>
		</dd>
		<dd>
			<?php 
			$this->widget('manage.widget.UploaderWidget', array(
				'main_picture' 	=> isset($model['main_picture'])?$model['main_picture']:null, 
				'pictures' 		=> isset($model['pictures'])?$model['pictures']:null,
			));
			?>
		</dd>
		<dt>物流运费</dt>
		<dd>
			<strong>承担运费：</strong>
			<label><input type="radio" name="Goods[assumer]" value="buyer" <?php echo isset($model['assumer']) && $model['assumer'] == 'buyer'?'checked="checked"':'' ?> /> 买家承担</label>
			<label><input type="radio" name="Goods[assumer]" value="seller" <?php echo isset($model['assumer']) && $model['assumer'] == 'seller'?'checked="checked"':'' ?>/> 卖家承担</label>
		</dd>
		<dd class="fee_dd">
			<strong><label for="fee_set">运费：</label></strong>
				<input type="radio" name="Goods[fee_type]" value="1" <?php echo isset($model['fee_type']) && $model['fee_type'] == 1?'checked="checked"':'' ?> id="fee_set">
				<label for="fee_set">平邮：</label><input type="text" name="Goods[post]" value="<?php echo isset($model['post'])?$model['post']:'0.00'?>" rule="^\d+\.?\d{0,2}$">
				快递：<input type="text" name="Goods[express]" value="<?php echo isset($model['express'])?$model['express']:'0.00'?>" rule="^\d+\.?\d{0,2}$">
				EMS：<input type="text" name="Goods[ems]" value="<?php echo isset($model['ems'])?$model['ems']:'0.00'?>" rule="^\d+\.?\d{0,2}$"><br>
		</dd>
		<dd class="fee_dd">
			<strong>货到付款：</strong>
			<label><input type="radio" name="Goods[fee_type]" value="2" <?php echo isset($model['fee_type']) && $model['fee_type'] == 2?'checked="checked"':'' ?>> 货到付款</label>
		</dd>
		<dt>售后/保障/服务</dt>
		<dd>
			<strong>售后支持：</strong>
			<?php 
			$this->widget('manage.widget.EnumsSelectorWidget', array(
				'code' => 'after_sale',
				'name' => 'Goods[after_sale][]',
				'values' => isset($model['after_sale'])?$model['after_sale']:null
			));
			?>
		</dd>
		<?php echo $this->renderPartial('../common/seo', array('model'=>$model));?>	
		<dt>高级设置</dt>
		<dd>
			<strong>页面模板：</strong>
			<?php echo YHtml::activeTextField($model, 'tpl_view', array('model'=>'Goods', 'next_focus'=>''))?>
			<p>指定明细页面使用模板</p>
		</dd>
		<dd>
			<strong>页面名称：</strong>
			<?php echo YHtml::activeTextField($model, 'name_view', array('model'=>'Goods', 'next_focus'=>''))?>
			<p>静态文件名</p>
		</dd>
	</dl>
	<div class="buttons right">
		<?php echo YHtml::activeHiddenField($model, '_id', array('model'=>'Goods'))?>
		<input type="button" class="button save_btn" value="保存"/>
	</div>
<?php $this->endWidget(); ?>
